﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ResultsManagementSystem
{
    public partial class StudentInterface : Form
    {
        private String number;

        public StudentInterface(String number)
        {
            InitializeComponent();

            this.number = number;
        }

        //查询一个同学的所有成绩
        private void queryAllButton_Click(object sender, EventArgs e)
        {
            Score score = new Score();

            ScoreDao scoreDao = new ScoreDao();

            List<Score> scoreList = scoreDao.queryStudentAllScore(this.number);

            StudentSubjectDao studentSubjectDao = new StudentSubjectDao();

            StudentDao studentDao = new StudentDao();

            SubjectDao subjectDao = new SubjectDao();

            Student student = studentDao.querryStudentByNumber(this.number);

            StudentSubject studentSubject = new StudentSubject();

            List<StudentSubject> studentSubjectList = studentSubjectDao.querryStudentSubjectByStudentId(student.getId());

            //清空成绩显示
             scoreListBox.Items.Clear();

            //将学生所有的成绩显示
            for (int i = 0; i < scoreList.Count;i++ )
            {
                studentSubject = studentSubjectList.ElementAt(i);

                score = scoreList.ElementAt(i);

                scoreListBox.Items.Add(subjectDao.querrySubjectById(studentSubject.getSubjectId()).getName() + ":" + score.getScore());
            }


        }

        private void querySingleButton_Click(object sender, EventArgs e)
        {
            ScoreDao scoreDao = new ScoreDao();

            Score score = scoreDao.queryScoreBySubjectNameAndStudentNumber(this.subjectNameBox.Text,this.number);

            if(score == null)
            {
                MessageBox.Show("没有选课，或成绩未公布！");
            }
            else
            {
                //清空成绩显示
                scoreListBox.Items.Clear();

                scoreListBox.Items.Add(this.subjectNameBox.Text + ":" + score.getScore().ToString());
            }
        }
    }
}
